package com.hu.zhcc.shiro.controller;

import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.hu.zhcc.shiro.dao.Tj_TMemberDataMapper;
import com.hu.zhcc.shiro.entity.tj.TEntity;
import com.hu.zhcc.shiro.entity.tj.TMemberData;
import com.hu.zhcc.shiro.service.Tj_TMemberDataService;
import com.hu.zhcc.shiro.service.Tj_TMemberExaminationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/tjbg")
public class TjTijianbaogaoController {
    @Autowired
    private Tj_TMemberExaminationService tjTMemberExaminationService;//会员检查表
    @Autowired
    private Tj_TMemberDataMapper tjTMemberDataMapper;//体检报告表
    @Autowired
    private Tj_TMemberDataService tjTMemberDataService;//体检报告表

    @GetMapping("/tjbgAll/{id}")
    public List<TMemberData> queryById(@PathVariable("id") int id){
        List<TMemberData> tMemberData = tjTMemberDataMapper.selectByPrimaryKey(id);
        return tMemberData;
    }
    @PutMapping("")
    public int wcbg(@RequestBody TEntity entity){
        Gson gson=new Gson();
        List<TMemberData> statusLs = gson.fromJson(entity.getChek(),new TypeToken<List<TMemberData>>(){}.getType());
        Integer id = statusLs.get(0).gettMemberId();
        tjTMemberDataMapper.deleteByPrimaryKey(id);//先删除
        for(TMemberData t:statusLs){
            System.out.println(t);
            tjTMemberDataMapper.insert(t);//添加
        }
        tjTMemberExaminationService.updstatus(String.valueOf(id));//修改状态
        return 1;
    }
}
